package aimis.controller;

import aimis.domain.Chicken;
import aimis.dto.Res;
import aimis.repo.ChickenMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/chicken")
public class ChickenController {

    @Autowired
    ChickenMapper chickenMapper;

    //查询
    @GetMapping("/selectCen")
    public Res<?> select(){
        return Res.success(chickenMapper.selectList(null),"");
    }
    //新增
    @PostMapping("/insertCen")
    public Res<?> insert(@RequestBody Chicken chicken){
        return Res.success(chickenMapper.insert(chicken),"");
    }
    //修改
    @PostMapping("/UpdateCen")
    public Res<?> update(@RequestBody Chicken chicken){
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",chicken.getId());
        return Res.success(chickenMapper.update(chicken,queryWrapper),"");
    }

    //删除
    @GetMapping("/deleteCen/{id}")
    public Res<?> delete(@PathVariable Long id){
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return Res.success(chickenMapper.delete(queryWrapper),"");
    }
}
